package main

import (
	"container/ring"
	"fmt"
	"time"
)

var (
	limitBucket int = 6 // 滑动窗口个数
	head *ring.Ring     // 环形队列（链表）
)

func main() {

	// 初始化滑动窗口
	head = ring.New(limitBucket)
	for i := 0; i < limitBucket; i++ {
		head.Value = 0
		head = head.Next()
	}
	// 启动执行器
	go func() {
		timer := time.NewTicker(time.Second * 3)
		for range timer.C { // 定时每隔3秒刷新一次滑动窗口数据
			fmt.Println(head.Value)
			head.Value = 0
			head = head.Next()
		}
	}()

	for i := 0;i < 100;i++{
		head.Value = i
		time.Sleep(time.Millisecond * 500)
	}

}
